package com.cart.protocol.analyze;


import com.cart.protocol.ProtocolDefine;
import com.cart.utils.FormatUtils;

/*
    ┏━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ 
       Author   :  lixiaodaoaaa
       Date     :  2020-01-16
       Time     :  17:12
    ┗━━━━━━━━━━━━━━━━━━━━━━━━━━━┛
 */
public class Co2RespAnalyze extends RespAnalyze {

    private static final String TAG = "OXYGEN";


    public Co2RespAnalyze(String rawDeviceInfo) {
        super(rawDeviceInfo);
    }


    @Override
    public Co2RespAnalyze analyze() {

        //读取氧气：10 0402  ff    1000
        //设置氧气：20 0401  bb    400b
        //停止氧气：20 0401  aa    00

        StringBuilder resultBuilder = new StringBuilder();
        switch (operatorCmd.toUpperCase()) {
            case ProtocolDefine.OperateCommand.READ:
                resultBuilder.append("读取");
                break;
            case ProtocolDefine.OperateCommand.SET:
                resultBuilder.append("设置");
                break;
            case ProtocolDefine.OperateCommand.CLOSE:
                resultBuilder.append("停止");
                break;
            default:
                break;
        }

        resultBuilder.append("二氧化碳");
        switch (commandWordRes.toUpperCase()) {
            case ProtocolDefine.CommandWordRes.ACTION_SUCCESS:
                resultBuilder.append("成功");
                break;
            case ProtocolDefine.CommandWordRes.ACTION_FAIL:
                resultBuilder.append("失败");
                break;
            case ProtocolDefine.CommandWordRes.READ_SUCCESS:
                resultBuilder.append("成功");
                break;
            case ProtocolDefine.CommandWordRes.READ_FAIL:
                resultBuilder.append("失败");
                break;
            default:
                break;
        }

        if (!operatorCmd.toUpperCase().equals(ProtocolDefine.OperateCommand.CLOSE)) {
            String oxygenData = rawDeviceInfo.substring(length - 4, length);
            String hexData = FormatUtils.revertString(oxygenData);
            int oxygenIntValue = FormatUtils.hexString2IntValue(hexData);
            String formatterOxygenData = ScoreFormatter.getShowValue(oxygenIntValue / 100f) + "%";
            resultBuilder.append("  ");
            resultBuilder.append("二氧化碳值是");
            resultBuilder.append(formatterOxygenData);
            report = resultBuilder.toString();
            return this;
        }
        report = resultBuilder.toString();
        return this;
    }

}
